package com.bytz.modules.cms.listener;

import com.bytz.modules.cms.domain.impl.price.*;
import com.bytz.modules.cms.domain.manager.CmsManager;
import com.bytz.modules.cms.domain.manager.CmsManagerWithoutResellerDiscount;
import com.bytz.modules.cms.domain.manager.ProductPriceManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class CmsConfig {

    /**
     * 创建Mall管理器
     */
    @Bean
    public CmsManager mallManager(ProductBasePriceComputer priceComputer,
                                  ProductLineLimitComputer productLineLimitComputer,
                                  ResellerLimitComputer resellerLimitComputer,
                                  ResellerLevelDiscountComputer resellerLevelDiscountComputer,
                                  CategoryDiscountComputer categoryDiscountComputer,
                                  ResellerOffsetComputer resellerOffsetComputer) {
        CmsManager cmsManager = new CmsManager();

        ProductPriceManager productPriceManager = new ProductPriceManager();
        productPriceManager.addPriceComputer(priceComputer);
        productPriceManager.addPriceComputer(productLineLimitComputer);
        productPriceManager.addPriceComputer(resellerLimitComputer);
        productPriceManager.addPriceComputer(resellerLevelDiscountComputer);
        productPriceManager.addPriceComputer(categoryDiscountComputer);
        productPriceManager.addPriceComputer(resellerOffsetComputer);

        cmsManager.setProductPriceManager(productPriceManager);

        return cmsManager;
    }

    /**
     * 创建用于计算不包含经销商独占优惠的Manager
     */
    @Bean
    public CmsManagerWithoutResellerDiscount mallManagerWithoutResellerDiscount(ProductBasePriceComputer priceComputer,
                                                                                ProductLineLimitComputer productLineLimitComputer,
                                                                                ResellerLevelDiscountComputer resellerLevelDiscountComputer,
                                                                                CategoryDiscountComputer categoryDiscountComputer) {
        CmsManagerWithoutResellerDiscount cmsManager = new CmsManagerWithoutResellerDiscount();

        ProductPriceManager productPriceManager = new ProductPriceManager();
        productPriceManager.addPriceComputer(priceComputer);
        productPriceManager.addPriceComputer(productLineLimitComputer);
        productPriceManager.addPriceComputer(resellerLevelDiscountComputer);
        productPriceManager.addPriceComputer(categoryDiscountComputer);

        cmsManager.setProductPriceManager(productPriceManager);

        return cmsManager;
    }
}
